<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.model' );
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_ecommerce'.DS.'tables');	

class EcommerceModelList extends JModel
{
	var $_catid = 0;
	
	function __construct()
	{
		global $mainframe;
		parent::__construct();
		$catid = intval(JRequest::getVar('catid', 2));
		$this->_catid = $catid;		
	}
	function getList()
	{
		$query = "SELECT id, name FROM #__pr_category WHERE parent_id = ".$this->_catid;			
		$this->_db->setQuery($query);
		$cats = $this->_db->loadObjectList();
		
		$i = 0;
		foreach($cats as $cat){
			$query = "SELECT p.*, com.name as com_name FROM #__pr_product p 
			LEFT JOIN #__pr_product_category pc on p.id = pc.product_id 
			LEFT JOIN #__pr_category c on c.id = pc.category_id 
			LEFT JOIN #__pr_company com on com.id = p.manufacturer  
			WHERE p.published = 1 AND c.id = ".$cat->id;
			$this->_db->setQuery($query);	
			$cats[$i]->products = $this->_db->loadObjectList();
			$i++;
		}
		return $cats;
	}
	
	function getInfo(){
		$query = "SELECT name FROM #__pr_category WHERE id = ".$this->_catid;
		$this->_db->setQuery($query);	
		$info = $this->_db->loadResult();
		return $info;
	}
}
?>